/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.yucc.girlimage.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.actionbarsherlock.app.SherlockFragment;
import com.umeng.analytics.MobclickAgent;
import com.yucc.girlimage.R;

/**
 * The main fragment that powers the ImageCategoryFragment screen. Fairly straight
 * forward GridView implementation with the key addition being the ImageWorker
 * class w/ImageCache to load children asynchronously, keeping the UI nice and
 * smooth and caching thumbnails for quick retrieval. The cache is retained over
 * configuration changes like orientation change so the images are populated
 * quickly as the user rotates the device.
 */
public class ImageCategoryFragment extends SherlockFragment implements
		OnClickListener {
	private static final String TAG = "ImageCategoryFragment";

	private View mPurityImageView;
	private View mSexyImageView;
	private View mShowGirlImageView;
	private View mBlackYarmImageView;
	private View mAutoDyneImageView;

	/**
	 * Empty constructor as per the Fragment documentation
	 */
	public ImageCategoryFragment() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setHasOptionsMenu(true);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		final View v = inflater.inflate(R.layout.fragment_image_category,
				container, false);
		
		mAutoDyneImageView = v.findViewById(R.id.imageview_down_left) ;
		mBlackYarmImageView = v.findViewById(R.id.imageview_up_right_down) ;
		mPurityImageView =  v.findViewById(R.id.imageview_up_right_top) ;
		mSexyImageView =  v.findViewById(R.id.imageview_up_left) ;
		mShowGirlImageView = v.findViewById(R.id.imageview_down_right) ;

		mAutoDyneImageView.setOnClickListener(this) ;
		mBlackYarmImageView.setOnClickListener(this) ;
		mPurityImageView.setOnClickListener(this) ;
		mSexyImageView.setOnClickListener(this) ;
		mShowGirlImageView.setOnClickListener(this) ;
		
		return v;
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onPause() {
		super.onPause();
	}

	// @Override
	// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	// inflater.inflate(R.menu.main_menu, menu);
	// }
	//
	// @Override
	// public boolean onOptionsItemSelected(MenuItem item) {
	// switch (item.getItemId()) {
	// case R.id.clear_cache:
	// final ImageCache cache = mImageWorker.getImageCache();
	// if (cache != null) {
	// mImageWorker.getImageCache().clearCaches();
	// DiskLruCache.clearCache(getActivity(), ImageFetcher.HTTP_CACHE_DIR);
	// Toast.makeText(getActivity(), R.string.clear_cache_complete,
	// Toast.LENGTH_SHORT).show();
	// }
	// return true;
	// }
	// return super.onOptionsItemSelected(item);
	// }

	@Override
	public void onClick(View v) {
		MobclickAgent.onEvent(getSherlockActivity(), "category",(String)v.getTag()) ;
		final Intent i = new Intent(getActivity(), ImageGridActivity.class);
		i.putExtra(ImageGridFragment.EXTRA_CATEGORY ,(String)v.getTag());
		i.putExtra(ImageGridFragment.EXTRA_IS_CATEGORY_REQUEST ,true);
		startActivity(i);
	}
}
